package com.qiguliuxing.dts.service.base;

import com.qiguliuxing.dts.db.dao.DtsSeckillSubMapper;
import com.qiguliuxing.dts.db.dao.ex.SeckillSubMapperEx;
import com.qiguliuxing.dts.db.domain.DtsSeckillSub;
import com.qiguliuxing.dts.db.bean.DtsUserSeckillSubInfo;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.time.LocalDateTime;
import java.util.List;
import java.util.Map;

@Service
public class DtsUserSeckillSubService {

	@Resource
	private DtsSeckillSubMapper dtsUserSeckillSubMapper;

	@Resource
	private SeckillSubMapperEx seckillSubMapperEx;
	
	public List<DtsUserSeckillSubInfo> selectNotifyUser(Map<String, Object> params){
		return seckillSubMapperEx.selectNotifyUser(params);
	}

	/**
	 *
	 * @param id
	 */
	public void updateNoticed(Integer id){
		seckillSubMapperEx.updateNoticed(id);
	}

	public Integer selectNotifyExists(Map<String, Object> params){
		return seckillSubMapperEx.selectNotifyExists(params);
	}

	/**
	 * 用户点击订阅秒杀消息提醒
	 * @param userId
	 * @param goodsId
	 */
	public void subscribe(Integer userId, Integer goodsId, Integer timeStatus) {
		DtsSeckillSub sub = new DtsSeckillSub();
		sub.setGoodsId(goodsId);
		sub.setUserId(userId);
		sub.setSubTime(LocalDateTime.now());
		sub.setStatus(false);
		if (timeStatus == 0) {
			// 今日提醒
			sub.setToSendDate(LocalDateTime.now());
		} else if (timeStatus == 2) {
			// 明日提醒
			sub.setToSendDate(LocalDateTime.now().plusDays(1));
		}
		dtsUserSeckillSubMapper.insert(sub);
	}
}
